package com.example.smartcity_poverty.ui.Home.adapter

import android.content.Intent
import androidx.fragment.app.Fragment
import com.example.smartcity_poverty.App
import com.example.smartcity_poverty.Base.BaseRecyclerAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.util.Util.glide
import com.example.smartcity_poverty.ui.AllService.ActivityManAge.ManAgeActivity
import com.example.smartcity_poverty.ui.AllService.Attorneys.AttorneysActivity
import com.example.smartcity_poverty.ui.AllService.DataAnalysis.DataAnalysisActivity
import com.example.smartcity_poverty.ui.AllService.GovernmentHotLine.GmHotLineActivity
import com.example.smartcity_poverty.ui.AllService.JobSearch.JobSearchActivity
import com.example.smartcity_poverty.ui.AllService.LivingPayment.LivingPaymentActivity
import com.example.smartcity_poverty.ui.AllService.LogisticsQuery.LogisticsQueryActivity
import com.example.smartcity_poverty.ui.AllService.LoveDonate.LoveDonateActivity
import com.example.smartcity_poverty.ui.AllService.NumberBook.NumberBookActivity
import com.example.smartcity_poverty.ui.AllService.OA.OaActivity
import com.example.smartcity_poverty.ui.AllService.PetHospital.PetHospitalActivity
import com.example.smartcity_poverty.ui.AllService.RubbishClassify.RubbishClassifyActivity
import com.example.smartcity_poverty.ui.AllService.SeeMovie.SeeMovieActivity
import com.example.smartcity_poverty.ui.AllService.SeekHouse.SeekHouseActivity
import com.example.smartcity_poverty.ui.AllService.SmartBus.SmartBusActivity
import com.example.smartcity_poverty.ui.AllService.SmartTrafficControl.SmartTcActivity
import com.example.smartcity_poverty.ui.AllService.StopWhere.StopWhereActivity
import com.example.smartcity_poverty.ui.AllService.TakeOutTr.TakeOutHomeActivity
import com.example.smartcity_poverty.ui.AllService.TrafficViolationsInquiry.TviActivity
import com.example.smartcity_poverty.ui.AllService.VolunteerService.VolunteerServiceActivity
import com.example.smartcity_poverty.ui.AllService.YouthPost.YouthPostActivity
import com.example.smartcity_poverty.ui.Home.HomeFragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.android.synthetic.main.re_item_more.*
import kotlinx.android.synthetic.main.re_item_more.view.*

/**
 *  created by ikun
 *  ANDROID STUDIO - version 4.0
 *  email: jinkunwei41@gmail.com
 * --------------------------------
 *  主页全部服务填充
 **/
class MoreAdapter(
    private val SS: Boolean,
    private val size: Int,
    private val fr: Fragment,
    private val list: MutableList<HomeFragment.HomeMoreEntity>,
    layoutId: Int
) : BaseRecyclerAdapter<HomeFragment.HomeMoreEntity>(list, layoutId){
    override fun setData(
        view: BaseViewHolder.ViewFind,
        data: HomeFragment.HomeMoreEntity,
        position: Int,
        holder: BaseViewHolder
    ) {

        // 添加动画
        holder.itemView.animation = App.getAnimationTopAndBottom()


        // 对所有服务进行排序（从高到低）
        list.sortByDescending { it.id }

        val d = list[position]

        // 如果是在主页传过来的全部服务图片侧显示全部服务这个模块
        // 不是为空的话就什么都不显示
        if (d.moreUrl.isEmpty()){
            holder.viewFind.moreImage.setImageResource(R.mipmap.ic_launcher_round)
            holder.viewFind.moreTitle.text = d.moreTitle
        }else{
            glide(d.moreUrl, holder.itemView.moreImage)
            holder.viewFind.moreTitle.text = d.moreTitle
        }

        if (SS){
            if (position == 9) {
                holder.viewFind.moreImage.setImageResource(R.mipmap.ic_launcher_round)
                holder.viewFind.moreTitle.text = "全部服务"
            }
        }

        val con = holder.viewFind.view?.context

        holder.itemView.setOnClickListener {
            if (holder.viewFind.moreTitle.text.toString() == "全部服务"){
                val nav = fr.requireActivity().findViewById<BottomNavigationView>(R.id.nav_view)
                nav.selectedItemId = R.id.navigation_dashboard
            }

            if (holder.viewFind.moreTitle.text.toString() == "停哪儿"){
                con?.startActivity(Intent(con, StopWhereActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "数字图书馆"){
                con?.startActivity(Intent(con, NumberBookActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "活动管理"){
                con?.startActivity(Intent(con, ManAgeActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "青年驿站"){
                con?.startActivity(Intent(con, YouthPostActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "爱心捐赠"){
                con?.startActivity(Intent(con, LoveDonateActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "政府服务热线"){
                con?.startActivity(Intent(con, GmHotLineActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "数据分析"){
                con?.startActivity(Intent(con, DataAnalysisActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "垃圾分类"){
                con?.startActivity(Intent(con, RubbishClassifyActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "律师咨询"){
                con?.startActivity(Intent(con, AttorneysActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "智慧巴士") {
                con?.startActivity(Intent(con, SmartBusActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "门诊预约") {
                con?.startActivity(Intent(con, OaActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "违章查询") {
                con?.startActivity(Intent(con, TviActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "找房子") {
                con?.startActivity(Intent(con, SeekHouseActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "智慧交管") {
                con?.startActivity(Intent(con, SmartTcActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "生活缴费") {
                con?.startActivity(Intent(con, LivingPaymentActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "看电影") {
                con?.startActivity(Intent(con, SeeMovieActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "志愿服务") {
                con?.startActivity(Intent(con, VolunteerServiceActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "找工作") {
                con?.startActivity(Intent(con, JobSearchActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "宠物医院") {
                con?.startActivity(Intent(con, PetHospitalActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "物流查询") {
                con?.startActivity(Intent(con, LogisticsQueryActivity::class.java))
            }

            if (holder.viewFind.moreTitle.text.toString() == "外卖订餐") {
                con?.startActivity(Intent(con, TakeOutHomeActivity::class.java))
            }

        }

    }

    override fun getItemCount(): Int {
        return  size
    }
}